package com.itheima.health.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

/**
 * 会员统计 DAO
 */
@Mapper
public interface MemberReportDao {



    /**
     * 查询当月的会员总数
     * @param month
     * @return
     */
    Integer selectCountByMonth(String month);

    /**
     * 插入
     * @param month
     * @param count
     */
    void insert(String month, Integer count);

    @Select("SELECT " +
            "(SELECT COUNT(*) FROM t_member WHERE DATE(regTime) = CURDATE()) AS todayNewMember,"+
            "(SELECT COUNT(*) FROM t_member WHERE YEARWEEK(regTime, 1) = YEARWEEK(CURDATE(), 1)) AS thisWeekNewMember, " +
            "(SELECT COUNT(*) FROM t_member WHERE MONTH(regTime) = MONTH(CURDATE()) AND YEAR(regTime) = YEAR(CURDATE())) AS thisMonthNewMember, " +
            "(SELECT COUNT(*) FROM t_member) AS totalMember")
    @Results({
            @Result(property = "todayNewMember", column = "todayNewMember"),
            @Result(property = "thisWeekNewMember", column = "thisWeekNewMember"),
            @Result(property = "thisMonthNewMember", column = "thisMonthNewMember"),
            @Result(property = "totalMember", column = "totalMember")
    })
    Map<String,Long> findMemberStats();
}
